Page({
  data:{
    isincome:true,
    incomelist:[],
    paylist:[],
    isinput:true,
    incometotal:0,
    paytotal:0,
    inputval:''
  },
  click(e){
    console.log(e)
  if(e.currentTarget.dataset.name=='income'){
    this.setData({
      isincome:true
    })
  }else{
    this.setData({
      isincome:false
    })
  }
},
  add(){
    this.setData({
      isinput:!this.data.isinput
    })
  },
  confirm(e){
    console.log(e)
    let je =Number(e.detail.value) 
    let incomelist = this.data.incomelist
    let paylist = this.data.paylist
    if(this.data.isincome){
      incomelist.push(je)
      let incometotal = incomelist.reduce((sum,v)=>{
        return sum+=v
      },0)
      this.setData({
        incomelist,incometotal,
        isinput:false,
        inputval:''
      })
    }else{
      paylist.push(je)
      let paytotal = paylist.reduce((sum,v)=>{
        return sum+=v
      },0)
      this.setData({
        paylist,paytotal,
        isinput:false,
        inputval:''
      })
    }
  },
  onUnload(){
    this.onHide()
  },
  onHide(){
    console.log('onHide')
    let store=[this.data.incomelist,this.data.paylist,this.data.incometotal,this.data.paytotal]
       wx.setStorage({
         data:store,
         key:'money'
       })
  },
  onLoad(options){
    console.log('onLoad')
    wx.getStorage({
      key:'money'
    }).then(res=>{
      console.log(res)
      this.setData({
        incomelist:res.data[0],
        paylist:res.data[1],
        incometotal:res.data[2],
        paytotal:res.data[3]
      })
    })
  },
  change(e){
    console.log(e)
    this.setData({
      data:e.detail.value
    })
  }
})